import http from '../../utils/http';

const news = {
  state:{
    newsDate: 0,
    stories: [],
    topStories: []
  },
  mutations:{
    updateNews(state,news){
      state.newsDate = news.date;
      state.stories = [...news.top_stories,...news.stories];
    }
  },
  actions:{
    getZhiHuNews(context){
      http.getZhiHuNews().then(response => {
        context.commit('updateNews', response);
      }).catch(() =>{
        context.commit('showMessage', { message: '新闻接口请求失败，请联系作者修复！微信号：LeeYu2333' , type: 'error' });
      });;
    }
  }
}

export default news;